from flask import jsonify, current_app as app


def register_error_handlers(app):
    if app.debug:
        @app.errorhandler(Exception)
        def handle_error(e):
            app.logger.error(f"未处理异常: {str(e)}")
            return jsonify({"code": 0, "msg": f"服务器错误: {str(e)}"}), 500
